import { hexToRgba } from "./color";

export const createLinearGradientCanvas = (size = 64, color) => {
    const canvas = document.createElement('canvas');
    canvas.width = size;
    canvas.height = size;
    const ctx = canvas.getContext('2d');
    const linearGradient = ctx.createLinearGradient(0, 0, 0, size);
    linearGradient.addColorStop(0, hexToRgba(color, 1)); //将16进制写法转换从rgba写法
    linearGradient.addColorStop(0.2, hexToRgba(color, 0.5));
    linearGradient.addColorStop(1, 'transparent');
    ctx.fillStyle = linearGradient;
    ctx.fillRect(0, 0, size, size);
    return canvas;
};